package com.tommy.ddp.finder
{
	import com.tommy.ddp.GridDataManager;
	import com.tommy.ddp.box.DdpBox;
	import com.tommy.ddp.definition.AxisConfig;
	import com.tommy.ddp.grid.DdpGrid;
	import com.tommy.ddp.manager.DisposeBoxManager;
	
	import flash.geom.Point;

	public class FinderVo
	{
		public var x:uint;
		public var y:uint;
		public var start:uint;
		public var end:uint;
		public var axis:uint;
		public var isCrossed:Boolean;
		//
		private var boxList:Vector.<DdpBox>;
		
		
		public function FinderVo()
		{
		}
		
		public static function isCross(xVo:FinderVo,yVo:FinderVo):Point
		{
			if((xVo.y >= yVo.start && xVo.y <= yVo.end) && (yVo.x >= xVo.start && yVo.x <= xVo.end))
			{
				return new Point(yVo.x,xVo.y);
			}
			else
				return null;
		}
		/**
		 * 该条数据中是否包括某个
		 * @param box
		 * @param axis
		 * @return 
		 * 
		 */		
		public static function containBox(box:DdpBox,vo:FinderVo,axis:uint):Boolean
		{
			if(!box)
				return false;
			//
			if(axis == AxisConfig.X_AXIS)
			{
				return (box.row == vo.y && (box.column >= vo.start && box.column <= vo.end));
			}
			else
			{
				return (box.column == vo.x && (box.row >= vo.start && box.row <= vo.end))
			}
		}
		/**
		 * 返回该条数据里棋子总数
		 * @return 
		 * 
		 */		
		public function get length():uint
		{
			return end - start + 1;
		}
		
		/**
		 * 消除格子（给格子置状态）
		 * 
		 */		
		public function disposeBox():Vector.<DdpBox>
		{
			var box:DdpBox;
			var vect:Vector.<DdpBox> = new Vector.<DdpBox>();
			
			boxList = new Vector.<DdpBox>();
			
			if(axis == AxisConfig.X_AXIS)
			{
				for(var i:uint = start;i <= end;i++)
				{
					box = GridDataManager.getBox(i,y);
					if(box)
						boxList.push(box);
				}
			}
			else
			{
				for(i = start;i <= end;i++)
				{
					box = GridDataManager.getBox(x,i);
					if(box)
						boxList.push(box);
				}
			}
			//
			for each(var b:DdpBox in boxList)
			{
				b.isInDisposeList = true;
			}
			for each(b in boxList)
			{
				var v:Vector.<DdpBox> = DisposeBoxManager.addDisposeBox(b);
				vect = vect.concat(v);
			}
			return vect;
		}
		
		public function getDPounchGridList():Vector.<DdpGrid>
		{
			var grid:DdpGrid;
			var box:DdpBox;
			var vect:Vector.<DdpGrid> = new Vector.<DdpGrid>();
			
			var sx:int;
			var ex:int;
			var sy:int;
			var ey:int;
			
			var i:int;
			var m:int;
			var n:int;
			
			if(axis == AxisConfig.X_AXIS)
			{
				for(i = start;i <= end;i++)
				{
					sx = i - 1;
					ex = i + 1;
					sy = y - 1;
					ey = y + 1;
					for(m = sx;m<=ex;m++)
					{
						for(n = sy;n<=ey;n++)
						{
							grid = GridDataManager.getGrid(m,n);
							if(grid)
								vect.push(grid);
						}
					}
				}
			}
			else
			{
				for(i = start;i <= end;i++)
				{
					sx = x - 1;
					ex = x + 1;
					sy = i - 1;
					ey = i + 1;
					for(m = sx;m<=ex;m++)
					{
						for(n = sy;n<=ey;n++)
						{
							grid = GridDataManager.getGrid(m,n);
							if(grid)
								vect.push(grid);
						}
					}
				}
			}
			
			return vect;
		}
	}
}